package com.spring.forum.config;


import com.spring.forum.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    private final List excludes =  Arrays.asList(
            "/**/*.html",  // 排除static目录下以 .html 结尾的路径
            "/blog-editormd/**", // 排除 blog-editormd 目录下的路径
            "/css/**", // 排除 css 目录下的路径
            "/js/**", // 排除 js 目录下的路径
            "/pic/**", // 排除 pic 目录下的路径
            "/user/login", // 排除登录路径
            "/**/*.ico" // 排除 .ico 路径
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  // 拦截器作用于所有路径
                .excludePathPatterns(excludes);  // 排除以下路径
    }
}
